﻿<phone:PhoneApplicationPage
    x:Class="BudgetManager.ExpenseReports"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 
    xmlns:amq="clr-namespace:AmCharts.Windows.QuickCharts;assembly=AmCharts.Windows.QuickCharts.WP"
    xmlns:ViewModels="clr-namespace:BudgetManager.ViewModels"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <phone:PhoneApplicationPage.Resources>
        <!--Data template for Header-->
        <DataTemplate x:Key="expensesGrpHeaderTemplate">
            <Border Background="Transparent" Padding="5">
                <Border Background="{StaticResource PhoneAccentBrush}" BorderBrush="{StaticResource PhoneAccentBrush}" BorderThickness="2" Width="Auto" 
         Height="Auto" Margin="0,0,18,0" HorizontalAlignment="Left">
                    <TextBlock Text="{Binding Key}" Foreground="{StaticResource PhoneForegroundBrush}" FontSize="48" Padding="6" 
            FontFamily="{StaticResource PhoneFontFamilySemiLight}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="{Binding ElementName=expensesList,Path=ActualWidth}"/>
                </Border>
            </Border>
        </DataTemplate>
        <!--Data Template For Items-->
        <DataTemplate x:Key="expensesItemTemplate">
            <StackPanel VerticalAlignment="Top" Orientation="Horizontal">
                <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu>
                        <toolkit:MenuItem Header="delete expense" Tap="onDeleteExpense"/>
                        <toolkit:MenuItem Header="edit expense" Tap="onEditExpense" />
                    </toolkit:ContextMenu>
                </toolkit:ContextMenuService.ContextMenu>
                <StackPanel Margin="5" Background="{StaticResource PhoneAccentBrush}">
                    <TextBlock  HorizontalAlignment="Center" Text="{Binding Date}" ></TextBlock>
                    <TextBlock HorizontalAlignment="Center" Text="{Binding Month}"></TextBlock>
                    <TextBlock HorizontalAlignment="Center" Text="{Binding Year}"></TextBlock>
                </StackPanel>
                <StackPanel Margin="5">
                    <TextBlock Text="{Binding ExpenseAmount}" />
                    <TextBlock Text="{Binding Comments}" />
                    <TextBlock Text="{Binding ExpenseId}" Visibility="Collapsed" />
                    <TextBlock Text="{Binding Category}" Visibility="Collapsed" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>
        <!--Data Template For JumpList-->
        <Style x:Key="ExpenseReportJumpListStyle" TargetType="phone:LongListSelector">
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate x:Name="ExpenseReportJumpList">
                        <Border Background="{StaticResource PhoneAccentBrush}" 
                                Width="Auto" 
                                Height="Auto" 
                                Margin="6">
                            <TextBlock Text="{Binding Key}" VerticalAlignment="Bottom" Style="{StaticResource PhoneTextLargeStyle}" TextWrapping="Wrap"/>
                        </Border>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </phone:PhoneApplicationPage.Resources>
    <Grid x:Name="LayoutRoot" Background="Transparent" d:DataContext="{d:DesignInstance Type=ViewModels:ExpenseReportViewModel, IsDesignTimeCreatable=True}">
        <!--Pivot Control-->
        <phone:Pivot Title="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}">
            <!--Pivot item one-->
            <phone:PivotItem Header="{Binding Path=LocalizedResources.Reports, Source={StaticResource LocalizedStrings}}">
                <phone:LongListSelector x:Name="expensesList" ItemsSource="{Binding GroupedExpenses}" GroupHeaderTemplate="{StaticResource expensesGrpHeaderTemplate}" ItemTemplate="{StaticResource expensesItemTemplate}" LayoutMode="List"  IsGroupingEnabled="True" HideEmptyGroups="True" JumpListStyle="{StaticResource ExpenseReportJumpListStyle}">
                </phone:LongListSelector>
            </phone:PivotItem>
            <phone:PivotItem Header="{Binding Path=LocalizedResources.Overview, Source={StaticResource LocalizedStrings}}">
                <ScrollViewer>
                    <StackPanel>
                        <StackPanel Name="panelwithData">
                            <StackPanel Name="balanceConfiguredWithinLimit" Visibility="Collapsed">
                                <TextBlock Text="{Binding Path=LocalizedResources.ConfiguredBalanceText, Source={StaticResource LocalizedStrings}}" Style="{StaticResource PhoneTextTitle2Style}"></TextBlock>
                                <TextBlock Name="txtRemaining" Style="{StaticResource PhoneTextTitle1Style}"></TextBlock>
                                <ProgressBar IsIndeterminate="False" Name="balanceProgess" Height="50" Width="400" HorizontalAlignment="Left">

                                </ProgressBar>
                            </StackPanel>
                            <StackPanel Name="balanceConfiguredExceedsLimit" Visibility="Collapsed">
                                <TextBlock Text="{Binding Path=LocalizedResources.BalanceExceededtext, Source={StaticResource LocalizedStrings}}" Style="{StaticResource PhoneTextTitle2Style}" Foreground="Red" TextWrapping="Wrap"></TextBlock>
                                <TextBlock Name="txtExceeded" Style="{StaticResource PhoneTextTitle1Style}"></TextBlock>
                            </StackPanel>
                            <StackPanel Name="balanceNotConfigured" Visibility="Collapsed">
                                <TextBlock Name="txtTotalExpense" Style="{StaticResource PhoneTextTitle2Style}"></TextBlock>
                                <TextBlock Name="txtDate" Style="{StaticResource PhoneTextAccentStyle}"></TextBlock>
                            </StackPanel>
                            <TextBlock Text="{Binding Path=LocalizedResources.CategoryWiseExpenseText, Source={StaticResource LocalizedStrings}}"></TextBlock>
                            <amq:PieChart Name="pieOverviewChart" TitleMemberPath="Title" ValueMemberPath="Value" Height="300"></amq:PieChart>
                            <TextBlock Text="{Binding Path=LocalizedResources.DateWiseExpenseText, Source={StaticResource LocalizedStrings}}"></TextBlock>
                            <amq:SerialChart CategoryValueMemberPath="Title" Name="datedExpenseChart" AxisForeground="{StaticResource PhoneAccentBrush}" Height="400" Foreground="{StaticResource PhoneAccentBrush}" GridStroke="{StaticResource PhoneSemitransparentBrush}">
                                <amq:SerialChart.Graphs>
                                    <amq:ColumnGraph ValueMemberPath="Value" Title="{Binding Path=LocalizedResources.DateFieldText, Source={StaticResource LocalizedStrings}}" Brush="{StaticResource PhoneInverseInactiveBrush}" />
                                </amq:SerialChart.Graphs>
                            </amq:SerialChart>
                        </StackPanel>
                        <StackPanel Visibility="Collapsed" Name="panelWithoutData">
                            <TextBlock Style="{StaticResource PhoneTextExtraLargeStyle}" TextWrapping="Wrap" Text="{Binding Path=LocalizedResources.NoDataText, Source={StaticResource LocalizedStrings}}"></TextBlock>
                        </StackPanel>
                    </StackPanel>
                </ScrollViewer>
            </phone:PivotItem>
        </phone:Pivot>
    </Grid>

</phone:PhoneApplicationPage>